package com.wiegand.gui.text {
	import com.wiegand.gui.IGuiElement;
	import com.wiegand.loader.CssLoader;
	import com.wiegand.util.CropPic;

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.AntiAliasType;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	/**
	 * @author kw
	 */
	 
	public class CssTextSpriteXML extends Sprite implements IGuiElement{	
		
		private var _xml : XMLList;
		
		public function CssTextSpriteXML( xml : XMLList ):void{
		
			_xml = xml;
			
			init();
		
		}
			
		private function init() : void {
				
			var s : String = _xml;
			var style : String = _xml.attribute( "style" );
			var width : int = int( _xml.attribute( "width" ) ); 
					
			var textSprite : Sprite = new Sprite();
			
			var textfield : TextField = new TextField();
							
			if( width != 0 ){
				textfield.width = width;
				textfield.wordWrap = true;			
				textfield.multiline = true;				
			}				
										
			textfield.autoSize = TextFieldAutoSize.LEFT;	
			textfield.selectable = false;					
			textfield.mouseWheelEnabled = false;				
			textfield.embedFonts = true;								
			textfield.mouseEnabled = false;								
			textfield.styleSheet = CssLoader.getInstance().getStyleSheet();
			textfield.htmlText = "<"+style+">"+s+"</"+style+">";	
						
			var css : Object = ( CssLoader.getInstance().getStyleSheet() as StyleSheet).getStyle( style );
							
			if( css["tf_antialiastype"] == "advanced" ) textfield.antiAliasType = AntiAliasType.ADVANCED;
			else textfield.antiAliasType = AntiAliasType.NORMAL;
						
			if( css["tf_sharpness"] != undefined ) textfield.sharpness = Number( css["tf_sharpness"] );			
			if( css["tf_thickness"] != undefined ) textfield.thickness = Number( css["tf_thickness"] );			
							
			var data : BitmapData = CropPic.get_opaqueBMD( textfield ) as BitmapData;
			var bmp : Bitmap = new Bitmap( data );
			textSprite.addChild( bmp );
		
//			var ding : Sprite = ColorRectangle.create(0xff0000, .3, textSprite.width, textSprite.height );
//			textSprite.addChild( ding );
			
			addChild( textSprite );
		}
		
		public function open(delay : Number = 0) : void {
		}
		
		public function close(delay : Number = 0) : void {
		}
		
		public function show(delay : Number = 0) : void {
		}
		
		public function hide(delay : Number = 0) : void {
		}
		
		public function destroy() : void {
		}
		
		public function resizeHandler() : void {
		}
	}
}
